```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Base64编码详解 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
            background-color: #f8f9fa;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #282c34;
            color: #abb2bf;
            border-radius: 8px;
            overflow: hidden;
        }
        .code-header {
            background-color: #1e2227;
            padding: 8px 16px;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            display: flex;
            align-items: center;
        }
        .code-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 8px;
        }
        .code-dot:nth-child(1) { background-color: #ff5f56; }
        .code-dot:nth-child(2) { background-color: #ffbd2e; }
        .code-dot:nth-child(3) { background-color: #27c93f; }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .mermaid {
            background-color: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body class="antialiased">
    <header class="hero-bg text-white py-20 px-4">
        <div class="container mx-auto max-w-4xl">
            <div class="flex flex-col items-center text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6 tracking-tight">Base64编码详解</h1>
                <p class="text-xl md:text-2xl font-light mb-8 max-w-3xl leading-relaxed">
                    二进制数据与文本之间的桥梁 — 探索Base64编码的奥秘与应用
                </p>
                <div class="flex space-x-4">
                    <a href="#intro" class="px-6 py-3 bg-white text-indigo-700 font-medium rounded-full hover:bg-gray-100 transition duration-300">
                        <i class="fas fa-book-open mr-2"></i>开始阅读
                    </a>
                    <a href="#demo" class="px-6 py-3 bg-transparent border-2 border-white text-white font-medium rounded-full hover:bg-white hover:text-indigo-700 transition duration-300">
                        <i class="fas fa-code mr-2"></i>代码示例
                    </a>
                </div>
            </div>
        </div>
    </header>

    <main class="container mx-auto max-w-4xl px-4 py-12">
        <section id="intro" class="mb-20">
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <span class="bg-indigo-500 w-3 h-8 rounded-full mr-3"></span>
                        <h2 class="text-3xl font-bold text-gray-800">为什么要使用Base64</h2>
                    </div>
                    
                    <div class="prose max-w-none">
                        <p class="text-lg text-gray-700 mb-6">
                            Base64 <span class="font-semibold text-indigo-600">主要用途不是加密</span>，而是把一些二进制数转成普通字符，方便在网络上传输。由于一些二进制字符在传输协议中属于控制字符，不能直接传送，所以需要转换一下才可以。
                        </p>
                        <p class="text-lg text-gray-700 mb-6">
                            由于某些系统中只能使用ASCII字符，Base64就是用来将非ASCII字符的数据转换成ASCII字符的一种方法，Base64特别适合在http，mime协议下快速传输数据。比如网络中图片的传输。
                        </p>
                        <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-6 rounded">
                            <div class="flex">
                                <div class="flex-shrink-0">
                                    <i class="fas fa-info-circle text-blue-500 text-xl"></i>
                                </div>
                                <div class="ml-3">
                                    <p class="text-sm text-blue-700">
                                        Base64，并非安全领域下的加密解密算法。虽然经常遇到所谓的base64的加密解密。但base64只能算是一个编码算法，对数据内容进行编码来适合传输。
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="mt-10">
                        <div class="mermaid">
                            graph LR
                                A[二进制数据] -->|Base64编码| B[ASCII文本]
                                B -->|Base64解码| A
                                C[传输协议限制] -->|只允许ASCII| B
                                D[图片/文件传输] -->|使用Base64| E[安全传输]
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="demo" class="mb-20">
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div class="card bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-file-code text-indigo-500 mr-3 text-xl"></i>
                            <h3 class="text-2xl font-bold text-gray-800">Base64工具类</h3>
                        </div>
                        <div class="code-block">
                            <div class="code-header">
                                <div class="code-dot"></div>
                                <div class="code-dot"></div>
                                <div class="code-dot"></div>
                                <span class="text-xs text-gray-400 ml-2">Base64Utils.java</span>
                            </div>
                            <pre class="p-4 overflow-x-auto text-sm"><code class="language-java">import java.util.Base64;

public class Base64Utils {

    // 解码
    private static Base64.Decoder decoder = Base64.getDecoder();

    // 编码
    private static Base64.Encoder encoder = Base64.getEncoder();

    // 使用Base64把字节数组编码成字符串
    public static String encode(byte[] bytes) {
        return encoder.encodeToString(bytes);
    }

    // 使用Base64字符串解码成字节数组
    public static byte[] decode(String data) {
        return decoder.decode(data);
    }
}</code></pre>
                        </div>
                    </div>
                </div>

                <div class="card bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-terminal text-indigo-500 mr-3 text-xl"></i>
                            <h3 class="text-2xl font-bold text-gray-800">Base64解编码字符串</h3>
                        </div>
                        <div class="code-block">
                            <div class="code-header">
                                <div class="code-dot"></div>
                                <div class="code-dot"></div>
                                <div class="code-dot"></div>
                                <span class="text-xs text-gray-400 ml-2">StringExample.java</span>
                            </div>
                            <pre class="p-4 overflow-x-auto text-sm"><code class="language-java">@Test
void contextLoads() throws Exception {
    String msg = "Hello 你好";
    String encode = Base64Utils.encode(msg.getBytes("utf-8"));
    System.out.println("base64编码后的内容："+encode);
    byte[] decode = Base64Utils.decode(encode);
    System.out.println("base64解码后的内容:"+new String(decode,0,decode.length,"utf-8"));
}</code></pre>
                        </div>
                        <div class="mt-4 p-4 bg-gray-50 rounded-lg">
                            <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1653314099242-71d4b12d-5d91-4ef1-9cde-c415d003f3e7.png" alt="Base64字符串编码示例" class="rounded-lg shadow-md">
                        </div>
                    </div>
                </div>

                <div class="card bg-white rounded-xl shadow-md overflow-hidden md:col-span-2">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-file-image text-indigo-500 mr-3 text-xl"></i>
                            <h3 class="text-2xl font-bold text-gray-800">Base64解编码二进制数据</h3>
                        </div>
                        <div class="code-block mb-4">
                            <div class="code-header">
                                <div class="code-dot"></div>
                                <div class="code-dot"></div>
                                <div class="code-dot"></div>
                                <span class="text-xs text-gray-400 ml-2">BinaryExample.java</span>
                            </div>
                            <pre class="p-4 overflow-x-auto text-sm"><code class="language-java">@Test
void contextLoads2() throws Exception {
    // 二进制文件
    File file = new File("D:\\code\\idea2020\\test\\frame\\jwt\\src\\main\\resources\\Redis.png");
    byte[] bytes = FileCopyUtils.copyToByteArray(file);

    // 把二进制文件用Base64编码成字符串，方便在网络传输
    String encode = Base64Utils.encode(bytes);
    System.out.println("二进制文件base64编码后的内容:"+encode);

    // 把Base64编码的二进制字符串解码成字节数组
    byte[] decode = Base64Utils.decode(encode);
    new FileOutputStream("./demo.png").write(decode);
}</code></pre>
                        </div>
                        <div class="p-4 bg-gray-50 rounded-lg">
                            <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1653314192172-70344a52-f61b-47b7-a769-c1679bf059c5.png" alt="Base64二进制编码示例" class="rounded-lg shadow-md">
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8">
                <div class="flex items-center mb-6">
                    <span class="bg-indigo-500 w-3 h-8 rounded-full mr-3"></span>
                    <h2 class="text-3xl font-bold text-gray-800">Base64编码应用场景</h2>
                </div>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mt-8">
                    <div class="p-6 border border-gray-100 rounded-lg hover:border-indigo-100 hover:bg-indigo-50 transition duration-300">
                        <div class="flex items-center justify-center w-12 h-12 bg-indigo-100 rounded-full text-indigo-600 mb-4">
                            <i class="fas fa-globe text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-2">网络传输</h3>
                        <p class="text-gray-600">在HTTP等协议中传输二进制数据，如图片、文件等</p>
                    </div>
                    
                    <div class="p-6 border border-gray-100 rounded-lg hover:border-indigo-100 hover:bg-indigo-50 transition duration-300">
                        <div class="flex items-center justify-center w-12 h-12 bg-indigo-100 rounded-full text-indigo-600 mb-4">
                            <i class="fas fa-database text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-2">数据存储</h3>
                        <p class="text-gray-600">在XML、JSON等文本格式中嵌入二进制数据</p>
                    </div>
                    
                    <div class="p-6 border border-gray-100 rounded-lg hover:border-indigo-100 hover:bg-indigo-50 transition duration-300">
                        <div class="flex items-center justify-center w-12 h-12 bg-indigo-100 rounded-full text-indigo-600 mb-4">
                            <i class="fas fa-lock text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-2">简单混淆</h3>
                        <p class="text-gray-600">对数据进行基础编码，实现简单的内容隐藏</p>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <footer class="bg-gray-900 text-gray-300 py-12 px-4">
        <div class="container mx-auto max-w-4xl">
            <div class="flex flex-col items-center">
                <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition duration-300">
                    <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                </a>
                <div class="mt-6 flex space-x-4">
                    <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fab fa-twitter text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fab fa-weixin text-xl"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```